﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using Groundwork.Extensions;
using System.IO;

namespace ExtensionMethods.Test.Extensions
{
    [TestClass]
    public class ByteTests
    {
        [TestMethod]
        public void StringToByteArray()
        {
            string target = "hello world";
            byte[] converted = target.ToByteArray();

            converted.Length.Should().Be(11);
            converted[0].Should().Be(104);
            converted[1].Should().Be(101);
            converted[2].Should().Be(108);
            converted[3].Should().Be(108);
            converted[4].Should().Be(111);
            converted[5].Should().Be(32);
            converted[6].Should().Be(119);
            converted[7].Should().Be(111);
            converted[8].Should().Be(114);
            converted[9].Should().Be(108);
            converted[10].Should().Be(100);
        }

        [TestMethod]
        public void ByteArrayToStream()
        {
            string target = "hello world";
            byte[] converted = target.ToByteArray();
            Stream outputStream = converted.AsStream();
            outputStream.Length.Should().Be(11);
        }

        [TestMethod]
        public void ByteArrayToString()
        {
            string target = "hello world";
            byte[] converted = target.ToByteArray();
            converted.AsString().Should().Be(target);
        }

        [TestMethod]
        public void ByteArrayToProtected()
        {
            string target = "hello world";
            byte[] converted = target.ToByteArray();
            byte[] protectedContent = converted.AsProtected();
            protectedContent.Length.Should().BePositive();
        }

        [TestMethod]
        public void ByteArrayToProtectedWithEntropy()
        {
            string entropy = "additional";
            string target = "hello world";
            byte[] converted = target.ToByteArray();
            byte[] protectedContentNoEntopy = converted.AsProtected();
            protectedContentNoEntopy.Length.Should().BePositive();

            byte[] protectedContentWithEntropy = converted.AsProtected(entropy);
            protectedContentWithEntropy.Length.Should().BePositive(); 
            protectedContentNoEntopy.Should().NotEqual(protectedContentWithEntropy);
        
        }

    }
}
